<?php

class Engine_Data_Model_Menu {

    const PARENT_ADMIN = 1; // меню для админки
    protected $wherePermissions = '';

   public function __construct() {
       $permissions = Application_Bootstrap::getActiveUser()->getPermissions();
        if ($permissions)
            $this->wherePermissions = 'AND (permission IS NULL  OR permission IN ("' . implode('","', $permissions) . '")) ';
   }

   public function getMainMenuItems(){
       $db = Application_Bootstrap::getDbAdapter();
       $items = $db->select('SELECT * FROM `menu` WHERE `parentId` IS NULL AND statusId = 0 ' . $this->wherePermissions . ' ORDER BY `order`');
       return $items;
   }

    public function menuGetItemsByParent($id) {
        $db = Application_Bootstrap::getDbAdapter();
        $wherePermissions = $this->wherePermissions;
        $items = $db->select('SELECT * FROM `menu` WHERE `parentId` = ' . $id . '  AND statusId = 0 ' . $wherePermissions . '  ORDER BY `order`');
        return $items;
    }

}